{% extends 'base.html' %}

{% block content %}
<h1>{% if form.instance.pk %}编辑{% else %}新增{% endif %}请假申请</h1>
<form method="post">
    {% csrf_token %}
    {% load widget_tweaks %}
    <div class="mb-3">
        <label for="{{ form.start_date.id_for_label }}" class="form-label">{{ form.start_date.label }}</label>
        {% render_field form.start_date class="form-control" type="date"  %}
        {% for error in form.start_date.errors %}
            <div class="invalid-feedback d-block">{{ error }}</div>
        {% endfor %}
    </div>
    <div class="mb-3">
        <label for="{{ form.end_date.id_for_label }}" class="form-label">{{ form.end_date.label }}</label>
        {% render_field form.end_date class="form-control" type="date"  %}
        {% for error in form.end_date.errors %}
            <div class="invalid-feedback d-block">{{ error }}</div>
        {% endfor %}
    </div>
    <div class="mb-3">
        <label for="{{ form.leave_type.id_for_label }}" class="form-label">{{ form.leave_type.label }}</label>
        {% render_field form.leave_type class="form-control" %}
        {% for error in form.leave_type.errors %}
            <div class="invalid-feedback d-block">{{ error }}</div>
        {% endfor %}
    </div>
    <div class="mb-3">
        <label for="{{ form.attachment.id_for_label }}" class="form-label">{{ form.attachment.label }}</label>
        {% render_field form.attachment class="form-control" %}
        {% for error in form.attachment.errors %}
            <div class="invalid-feedback d-block">{{ error }}</div>
        {% endfor %}
    </div>
    {# 状态、审批人等字段可能由系统自动填充，用户无需输入，可根据需求决定是否隐藏 #}
    {% if form.instance.pk %}
    <div class="mb-3">
        <label for="{{ form.status.id_for_label }}" class="form-label">{{ form.status.label }}</label>
        {% render_field form.status class="form-control" %}
        {% for error in form.status.errors %}
            <div class="invalid-feedback d-block">{{ error }}</div>
        {% endfor %}
    </div>
    {% endif %}
    <button type="submit" class="btn btn-primary">提交</button>
    <a href="{% url 'core:leave_request_list' %}" class="btn btn-secondary">返回列表</a>
</form>
{% endblock %}